const db = require('../config/db');
const goodsModel = '../schema/goods.js';
const Mall = db.MallSequelize;

const Goods = Mall.import(goodsModel);

const getGoodsList = async function (){
    const result = await Goods.findAll();
    return result; 
}

const createGoods = async function(data){
    await Goods.create({
        goos_id: data.goodsId,
        goods_name: data.goodsName,
        goods_price: data.goodsPrice
    })
    return true
}

const updateGoods = async function(data){
    const result = await Goods.update({
        goods_name: data.goodsName,
        goods_price: data.goodsPrice
    },{
        where: {
            id: data.id
        }
    })
    return result;
}

const removeGooods = async function (data) {
    const result = await Goods.destroy({
        where: {
            id: data.id
        }
    })
    return result;
}
module.exports = { 
    getGoodsList,
    createGoods,
    updateGoods,
    removeGooods
}